// PathTreeNode.cpp: implementation of the CPathTreeNode class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "PathTreeNode.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CPathTreeNode::CPathTreeNode()
:m_l64Length(0)
,m_l64TotalLength(0)
{

}

CPathTreeNode::~CPathTreeNode()
{
	ClearChild();
}

CString CPathTreeNode::GetName()
{
	return m_csFullPath;
}

void CPathTreeNode::SetName(CString csName)
{
	m_csFullPath = csName;
}

LONG64 CPathTreeNode::GetLength()
{
	if (m_l64TotalLength > 0)
	{
		return m_l64TotalLength;
	}

	int nSize = m_arrChild.GetSize();
	if (nSize>0)
	{
		m_l64TotalLength = m_l64Length;
		int i;
		for (i=0; i<nSize; i++)
		{
			m_l64TotalLength += m_arrChild[i]->GetLength();
		}
		return m_l64TotalLength;
	}
	return m_l64Length;
}

void CPathTreeNode::SetLength(LONG64 len)
{
	m_l64Length = len;
}

BOOL CPathTreeNode::AddChild(CPathTreeNode* pNode)
{
	m_arrChild.Add(pNode);
	return TRUE;
}

void CPathTreeNode::ClearChild()
{
	int nSize = m_arrChild.GetSize();
	if ( nSize > 0)
	{
		int i;
		for (i=0; i<nSize; i++)
		{
			CPathTreeNode* pNode = m_arrChild.GetAt(i);
			delete pNode;
		}
		m_arrChild.RemoveAll();
	}
}

CPathTreeNode* CPathTreeNode::GetChild(int nChild)
{
	if (nChild < m_arrChild.GetSize())
	{
		return m_arrChild.GetAt(nChild);
	}
	else
	{
		return NULL;
	}
}

int CPathTreeNode::GetChildNum()
{
	return m_arrChild.GetSize();
}